package com.dykj.fireFighting.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.dykj.fireFighting.common.core.constant.WebsocketConstant;
import com.dykj.fireFighting.common.core.utils.JacksonUtil;
import com.dykj.fireFighting.common.starter.redisson.service.RedisService;
import com.dykj.fireFighting.web.base.websocket.CommonWebSocket;
import com.dykj.fireFighting.web.base.websocket.entity.MoreMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author fgc
 * @Date 2021/7/23 15:29
 * @ Description：
 */
@RestController
@RequestMapping("/analog/")
public class AnalogAlarmController {
    @Autowired
    private RedisService redisService;
    @RequestMapping("fire")
    public void analogFire(){
       List<String> userIds=new ArrayList<>();
       userIds.add("8");
       userIds.add("6");
       userIds.add("5");
       userIds.add("1");
       MoreMessage moreMessage=new MoreMessage();
       moreMessage.setUserIds(userIds.toArray(new String[0]));
       moreMessage.setCmd(WebsocketConstant.CMD_FIRE);
       moreMessage.setMsgId("4");
       moreMessage.setMsgTitle("火警通知");
       moreMessage.setMsgTxt("设备发出火警通知请及时确认");
        redisService.convertAndSend("channel:moreMessage",moreMessage);
    }
    @RequestMapping("ysFire")
    public void analogYsFire(){
        CommonWebSocket webSocket=new CommonWebSocket();
        JSONObject json=new JSONObject();
        json.put(WebsocketConstant.MSG_CMD,WebsocketConstant.CMD_YSFIRE);
        json.put(WebsocketConstant.MSG_ID,"4");
        json.put(WebsocketConstant.MSG_TITLE,"疑似火警通知");
        json.put(WebsocketConstant.MSG_TXT,"设备发出疑似火警通知请及时确认");
        webSocket.sendOneMessage("1",json.toJSONString());
    }
}
